package com.competition.web.admin.controller;

import javax.servlet.http.HttpServletRequest;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.param.impl.PageParam;
import com.admin.vo.ConfigVO;
import com.response.vo.ResponseModel;
import com.controller.base.AbstractCommonController;
import com.competition.web.entity.Config;
import com.competition.param.impl.ConfigAddParam;
import com.competition.param.impl.ConfigUpdateParam;
import com.competition.web.admin.service.IConfigService;
import com.basic.service.contract.IBaseService;

@RestController
@RequestMapping("config")
public class ConfigController extends AbstractCommonController<Config, PageParam> {
	private IConfigService service;


	public ConfigController(IConfigService service) {
		this.service = service;
	}

	/**
	 * 添加
	 * 
	 * @param <V>
	 * @param param
	 * @return
	 */
	@PostMapping("/add")
	public ResponseModel<Integer> insert(@RequestBody @Validated ConfigAddParam param,
			HttpServletRequest httpServletRequest) {
		int id = this.service.parseInsert(param, Config.class);

		return ResponseModel.<Integer>success(id);
	}

	@Override
	protected IBaseService<Config> getBaseService() {
		return this.service;
	}

	/**
	 * 添加
	 * 
	 * @param <V>
	 * @param param
	 * @return
	 */
	@PostMapping("/update")
	public ResponseModel<Integer> update(@Validated @RequestBody ConfigUpdateParam param,
			HttpServletRequest httpServletRequest) {
		int res = this.service.parseUpdate(param, Config.class);
		return ResponseModel.<Integer>success(res);
	}

	protected <VO> Class<VO> getTarget() {
		return (Class<VO>) ConfigVO.class;
	}
}